import java.util.HashMap;
import java.util.Map;

public class DecoderUtils {
    private static  Map<String,String> kvMap = new HashMap<>();
    static {
        kvMap.put("000000","@");
        kvMap.put("000001","A");
        kvMap.put("000010","B");
        kvMap.put("000011","C");
        kvMap.put("000100","D");
        kvMap.put("000101","E");
        kvMap.put("000110","F");
        kvMap.put("000111","G");
        kvMap.put("001000","H");
        kvMap.put("001001","I");
        kvMap.put("001010","J");
        kvMap.put("001011","K");
        kvMap.put("001100","L");
        kvMap.put("001101","M");
        kvMap.put("001110","N");
        kvMap.put("001111","O");
        kvMap.put("010000","P");
        kvMap.put("010001","Q");
        kvMap.put("010010","R");
        kvMap.put("010011","S");
        kvMap.put("010100","T");
        kvMap.put("010101","U");
        kvMap.put("010110","V");
        kvMap.put("010111","W");
        kvMap.put("011000","X");
        kvMap.put("011001","Y");
        kvMap.put("011010","Z");
        kvMap.put("011011","[");
        kvMap.put("011100","\\");
        kvMap.put("011101","]");
        kvMap.put("011110","^");
        kvMap.put("011111","–");
        kvMap.put("100000","");//空白
        kvMap.put("100001","!");
        kvMap.put("100010","\"");
        kvMap.put("100011","#");
        kvMap.put("100100","$");
        kvMap.put("100101","%");
        kvMap.put("100110","&");
        kvMap.put("100111","`");
        kvMap.put("101000","(");
        kvMap.put("101001",")");
        kvMap.put("101010","*");
        kvMap.put("101011","+");
        kvMap.put("101100",",");
        kvMap.put("101101","-");
        kvMap.put("101110",".");
        kvMap.put("101111","/");
        kvMap.put("110000","0");
        kvMap.put("110001","1");
        kvMap.put("110010","2");
        kvMap.put("110011","3");
        kvMap.put("110100","4");
        kvMap.put("110101","5");
        kvMap.put("110110","6");
        kvMap.put("110111","7");
        kvMap.put("111000","8");
        kvMap.put("111001","9");
        kvMap.put("111010",":");
        kvMap.put("111011",";");
        kvMap.put("111100","<");
        kvMap.put("111101","=");
        kvMap.put("111110",">");
        kvMap.put("111111","?");
    }

    public static String getStringFromStrBit(String strBit){

        System.out.println("待解析数据:"+strBit);

        //每6位找一次字母
        if(strBit==null||strBit.equals("")||(strBit.length()%6)!=0){
            System.out.println("格式非法，无法解析");
            return "";
        }
        StringBuilder sb = new StringBuilder();
        int index = strBit.length()/6;
        for (int i=0;i<index;i++){
            String bits = strBit.substring(i*6,i*6+6);
            String findStr = kvMap.get(bits);
            if(findStr==null){findStr="";}
            sb.append(findStr);
        }

        return sb.toString().trim();
    }



}
